package com.edu.edu.week_project01.activity.FactoryFragment;

import android.support.v4.app.Fragment;
import android.util.SparseArray;

import com.edu.edu.week_project01.activity.fragment.FirstFragment;
import com.edu.edu.week_project01.activity.fragment.SecondFragment;


/**
 * Created by Administrator on 9/24 0024.
 */
public class FactoryFragment {

    private static final int ONE = 0;
    private static final int TWO = 1;

    private static SparseArray<Fragment> fragments = new SparseArray();

    public static Fragment createFragment(int index) {
        Fragment fragment = fragments.get(index);
        if (fragment == null) {
            switch (index) {
                case ONE:
                    fragment = new FirstFragment();
                    break;
                case TWO:
                    fragment = new SecondFragment();
                    break;
            }
            fragments.put(index, fragment);
        }
        return fragment;
    }
}

